//
//  BETableViewExtension.swift
//  BasicExtensions
//
//  Created by Fanxx on 2018/3/23.
//  Copyright © 2018年 fanxx. All rights reserved.
//

import UIKit

extension UITableView {
    public func selectAll() {
        let sections = self.numberOfSections
        for i in 0..<sections {
            let rows = self.numberOfRows(inSection: i)
            for j in 0..<rows {
            let indexPath = IndexPath(row: j, section: i)
                self.selectRow(at: indexPath, animated: false, scrollPosition: .none)
            }
        }
    }
    public func deselectAll() {
        if let ips = self.indexPathsForSelectedRows {
            for ip in ips {
                self.deselectRow(at: ip, animated: false)
            }
        }
    }
    /// 获取行高
    public func heightForRow(at indexPath: IndexPath) -> CGFloat? {
        return cellForRow(at: indexPath)?.height ?? {
            let cell = dataSource?.tableView(self, cellForRowAt: indexPath)
            return cell?.contentView.systemLayoutSizeFitting(bounds.size, withHorizontalFittingPriority: .required, verticalFittingPriority: .defaultLow).height
        }()
    }
}
